package com.mobi.Survey.map;

import java.util.List;

import android.os.Bundle;
import android.view.View;
import android.widget.ListView;

import com.mobi.Survey.adapters.CustomAdapterFavorites;
import com.mobi.Survey.lib.db.FavoriteTable;
import com.mobi.Survey.lib.model.FavoritePojo;

public class FavoritesScreen extends MyTab {

	private ListView lvFavorites;
	private View tvNoData;

	private CustomAdapterFavorites adapter;

	@Override
	protected void onCreate(Bundle savedInstanceState) {

		super.onCreate(savedInstanceState);

		lvFavorites.setAdapter(adapter);

	}

	@Override
	protected void onStop() {
		finish();
		super.onStop();

	}

	@Override
	protected void onResume() {

		super.onResume();
		FavoriteTable table = new FavoriteTable(this);
		List<FavoritePojo> favorites = table.getAllFavorites();

		table.closeDB();
		if (favorites.size() == 0) {
			tvNoData.setVisibility(View.VISIBLE);
		} else if (tvNoData.getVisibility() == View.VISIBLE) {
			tvNoData.setVisibility(View.GONE);
		}

		adapter.setData(favorites);

		adapter.notifyDataSetChanged();

	}

	@Override
	protected void initUiVars() {
		lvFavorites = (ListView) findViewById(R.id.lvFavorites);
		adapter = new CustomAdapterFavorites(this);
		tvNoData = findViewById(R.id.tvNoData);
	}

	@Override
	protected int getLayoutId() {
		// TODO Auto-generated method stub
		return R.layout.favorites;
	}

}
